#!/bin/bash

set -e

export PATH="$PATH:/state/rust/cargo/bin"
export BUILD_ROOT=/state/build
export ONLINE_TESTS=1

echo "--- Install n2"
./tools/install-n2

echo "+++ Building and testing"
ln -sf out/node_modules .

if [ "$CLEAR_RUST" = "1" ]; then
    rm -rf $BUILD_ROOT/rust
fi

./ninja pylib qt check

echo "--- Ensure libs importable"
SKIP_RUN=1 ./run

echo "--- Check Rust libs"
cargo install cargo-deny
cargo deny check -A duplicate

echo "--- Cleanup"
rm -rf /tmp/* || true
